home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-11 | 3.2 KB | 129 lines |
- // This snippet creates a new dialog box
- // that prompts for a password
- // <File=PasswordDialog.java>
-
- //Title:
- //Version:
- //Copyright:
- //Author:
- //Company:
- //Description:
- //
-
- //<PACKAGE>
-
- import java.awt.*;
- import java.awt.event.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.control.*;
-
- public class PasswordDialog extends Dialog {
- Panel panel1 = new Panel();
- XYLayout xYLayout1 = new XYLayout();
- BevelPanel bevelPanel1 = new BevelPanel();
- Button button1 = new Button();
- Button button2 = new Button();
- Label label1 = new Label();
- TextField textField1 = new TextField();
-
- public PasswordDialog(Frame frame, String title, boolean modal) {
- super(frame, title, modal);
- try {
- jbInit();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- add(panel1);
- pack();
- }
-
- public PasswordDialog(Frame frame, String title) {
- this(frame, title, false);
- }
-
- public PasswordDialog(Frame frame) {
- this(frame, "", false);
- }
-
- public void jbInit() throws Exception {
- xYLayout1.setWidth(318);
- xYLayout1.setHeight(118);
- button1.setLabel("OK");
- button1.addActionListener(new PasswordDialog_button1_actionAdapter(this));
- button2.setLabel("Cancel");
- label1.setText("Enter Password");
- textField1.setEchoChar('@');
- button2.addActionListener(new PasswordDialog_button2_actionAdapter(this));
- this.addWindowListener(new PasswordDialog_this_windowAdapter(this));
- panel1.setLayout(xYLayout1);
- panel1.add(bevelPanel1, new XYConstraints(9, 10, 298, 65));
- bevelPanel1.add(label1, new XYConstraints(7, 2, 144, 24));
- bevelPanel1.add(textField1, new XYConstraints(5, 24, 265, 25));
- panel1.add(button1, new XYConstraints(61, 81, 74, 25));
- panel1.add(button2, new XYConstraints(164, 81, 77, 25));
- }
- //<Exclude>
- // Test case
- public static void main(String[] argv) {
- DecoratedFrame frame = new DecoratedFrame();
- frame.show();
- PasswordDialog pd = new PasswordDialog(frame, "Test", true);
- pd.show();
- //Get any results here
- System.out.println(pd.textField1.getText());
- System.exit(0);
- }
- //</Exclude>
-
- //OK
- void button1_actionPerformed(ActionEvent e) {
- dispose();
- }
-
- //Cancel
- void button2_actionPerformed(ActionEvent e) {
- dispose();
- }
-
- void this_windowClosing(WindowEvent e) {
- dispose();
- }
- }
-
- class PasswordDialog_button1_actionAdapter implements ActionListener {
- PasswordDialog adaptee;
-
- PasswordDialog_button1_actionAdapter(PasswordDialog adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.button1_actionPerformed(e);
- }
- }
-
- class PasswordDialog_button2_actionAdapter implements ActionListener {
- PasswordDialog adaptee;
-
- PasswordDialog_button2_actionAdapter(PasswordDialog adaptee) {
- this.adaptee = adaptee;
- }
-
- public void actionPerformed(ActionEvent e) {
- adaptee.button2_actionPerformed(e);
- }
- }
-
- class PasswordDialog_this_windowAdapter extends WindowAdapter {
- PasswordDialog adaptee;
-
- PasswordDialog_this_windowAdapter(PasswordDialog adaptee) {
- this.adaptee = adaptee;
- }
-
- public void windowClosing(WindowEvent e) {
- adaptee.this_windowClosing(e);
- }
- }
-